<template>
    <el-container style="min-height: 80vh">
      <el-main style="padding-top: 0;">
        <School :customer-info="customerInfo"/>
      </el-main>
    </el-container>
</template>

<script>
import { getDataListApi as getCustomerApi } from "@/api/crm/md/customer";
import School from "@/views/crm/md/school/index.vue";

export default {
  name: "CustomerDetail",
  components: {
    School
  },
  dicts: ['sys_key_customer_basis'],
  data() {
    return {
      // 客户id
      customerId: null,
      // 客户信息
      customerInfo: {
        address: "", // 地址
        basis: null, // 重点依据
        createBy: "", // 用户 *
        id: null, // id
        isImportant: 0, // 是否重点客户 0是普通 1是重点 *
        name: "", // 学校名 *
        province: "", // 省份 *
        remark: "", // 备注
        updateBy: "", // 更新人
      },
      // 重点客户下拉数据
      isImportantList: [
        {
          value: 0,
          label: '普通客户'
        },
        {
          value: 1,
          label: '重点客户'
        }
      ],
    }
  },
  mounted() {
    this.customerId = this.$route.query?.customerId ?? null
    this.getCustomer()
  },
  activated() {
    this.customerId = this.$route.query?.customerId ?? null
    this.getCustomer()
  },
  methods: {
    // 获取客户详细信息
    async getCustomer() {
      const res = await getCustomerApi({ id: this.customerId })
      if(res.code === 200 && res.rows[0]) {
        this.customerInfo = res.rows[0]
      }
    },
    // 获取根据list中的value返回label
    getListValue(data, list, value = 'value') {
      let label = ''
      list.map((item) => {
        if(+item[value] === +data) {
          label = item.label
        }
      })
      return label
    },
  }
}
</script>

<style scoped lang="scss">

</style>
